package com.a;

import com.ma.Foo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;

/**
 * @ClassName $Proxy0
 * @Author: mayongqiang
 * @DATE 2022/4/10 17:04
 * @Description: 手写一个jdk的代理类java文件 使用ASM技术将其转换为.class byte[]文件
 */
public class $Proxy0 extends Proxy implements Foo {
    static Method foo;

    static {
        try {
            foo = Foo.class.getDeclaredMethod("foo");
        } catch (NoSuchMethodException e) {
            throw new NoSuchMethodError(e.getMessage());
        }
    }

    protected $Proxy0(InvocationHandler h) {
        super(h);
    }

    @Override
    public void foo() {
        try {
            this.h.invoke(this, foo, null);
        } catch (Error | RuntimeException e) {
            throw e;
        } catch (Throwable throwable) {
            throw new UndeclaredThrowableException(throwable);
        }
    }
}
